#ifndef SHARELIST_H
#define SHARELIST_H

#include <QMenu>
#include <QNetworkAccessManager>
#include <QTimer>
#include <QWidget>

#include <common/common.h>

namespace Ui {
class sharelist;
}

class sharelist : public QWidget
{
    Q_OBJECT

public:
    explicit sharelist(QWidget *parent = 0);
    ~sharelist();

    void refreshFiles(Display cmd = Display::Normal);
private:
    void rightMenu(const QPoint& pos);

    void initListWidget();
    void addActionMenu();

    void downloadFilesAction();

    void clearshareFileList();
    void clearItems();
    void getUserFilesList(Display cmd = Display::Normal);
    void refreshFileItems();

    QByteArray setFilesListJson(int start, int count);
    void getFileJsonInfo(QByteArray data);

    void dealSelectdFile(QString cmd);
    void getFileProperty(FileInfo* info);
    void cancelSharingFile(FileInfo* info);
    void transferFile(FileInfo* info);
    QByteArray setShareFileJson(QString user, QString token, QString md5, QString filename);
    void addDownloadFiles();
    void dealFilePv(QString md5, QString filename);
signals:
    void loginAgainSignal();
    void gotoTransfer(TransferStatus status);
private:
    Ui::sharelist *ui;

    Common m_cm;
    QMenu* m_menu;
    QAction* m_downlodAction;
    QAction* m_propertyAction;
    QAction* m_cancelAction;
    QAction* m_saveAction;

    QMenu* m_menuEmpty;
    QAction* m_refreshAction;
    QAction* m_pvAscendingAction;
    QAction* m_pvDescendingAction;

    QNetworkAccessManager* m_manager;

    int m_start;
    int m_count;
    long m_userFilesCount;

    QList<FileInfo*> m_shareFileList;

    QTimer m_downloadTimer;
};

#endif // SHARELIST_H
